import {Injectable} from "@angular/core";

import {Http, Headers} from "@angular/http";

import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/timeout';


@Injectable()
export class servicess {
	  private headers = new Headers({'Content-Type': 'application/json; charset=utf-8'});
	  constructor(public http: Http) {
  };

    //定义一个出现错误时的回调函数
  	  private handleError(error: any): Promise<any> {
      return Promise.reject(error.message || error);
  }
  	/*  定义一个POST请求*/
  	 postMethod(url: string, param: any): Promise<any> {
      return this.http
      .post(url, JSON.stringify(param), {headers: this.headers})
      .timeout(2000) 	
      .toPromise()
      .then(response => response.json())
      .catch(this.handleError);

 }
}























